package ink.lovejinhu.leetcode;

import java.util.HashMap;

/**
 * @Author: jin
 * @Date: 2021/9/12 23:38
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0914 {
    /**
     * 找最大公约数
     *
     * @param deck
     * @return
     */
    public boolean hasGroupsSizeX(int[] deck) {


        HashMap<Integer, Integer> res = new HashMap<>();
        for (int i = 0; i < deck.length; i++) {
            if (res.containsKey(deck[i])) {
                Integer integer = res.get(deck[i]);
                integer++;
                res.put(deck[i], integer);
            } else {
                res.put(deck[i], 1);
            }
        }
        System.out.println(res);
        for (int i = 2; i <= deck.length; i++) {
            boolean flag = true;
            for (Integer temp : res.keySet()
            ) {
                int integer = res.get(temp);
                if (integer % i == 0) {
                    continue;
                } else {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                return true;
            }
        }

        return false;
    }

    public static void main(String[] args) {

        int[] test = {1, 2, 3, 4, 4, 3, 2, 1};
        Solution_0914 solution_0914 = new Solution_0914();
        boolean b = solution_0914.hasGroupsSizeX(test);
        System.out.println(b);
    }
}
